import 'package:flutter/material.dart';

import 'login/login_page.dart';
import 'application.dart';

import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:drm/ip_port_setting/ip_setting_page.dart';
import 'package:drm/home/main_page.dart';
import 'package:drm/chart_home_page/chart_page.dart';

import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {


  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      title: '正选DRM',
      theme: ThemeData(
          primarySwatch: Colors.blue,
          //0x4bd1fe
//          primaryColor: Color.fromARGB(0xFF, 0x4b, 0xd1, 0xfe)
//      primaryColor: Colors.yellow[700]
          // primaryColor: Colors.yellow[700]
//        primaryColor: Colors.lightBlue
          ),
      localizationsDelegates: [
        PickerLocalizationsDelegate.delegate, // 如果要使用本地化，请添加此行，则可以显示中文按钮
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('en', 'US'),
        const Locale('zh', 'CH'),
      ],
      home: AppPage(),
      routes: <String, WidgetBuilder>{
        'ipSetting': (BuildContext context) => IpPage(context),
        'mainPage': (BuildContext context) => MainSream(),
        'charPage': (BuildContext context) => ChartPage(),
      },
    );
  }
}

class AppPage extends StatefulWidget {
  @override
  _AppPageState createState() => _AppPageState();
}

class _AppPageState extends State<AppPage> {
  AppBloc appBloc = AppBloc();


  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();

    appBloc.dispose();
  }

  @override
  Widget build(BuildContext context) {
      return homePge(context);
  }


  Widget homePge(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 900, height: 1600,allowFontScaling:true)..init(context);
    Future.delayed(const Duration(seconds: 2), () {
      appBloc.dispatch(AppEvent.INI);
    });

    return BlocBuilder(
        bloc: appBloc,
        builder: (context, value) {
          return value ? loginPage(): firstPage();
        });
  }
  Widget  loginPage() {
    return LoginPage(context, title: 'drm');
  }

  Widget  firstPage() {
    return
      Material(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Container(
                height: 100,
                width: 100,
                margin: EdgeInsets.only(bottom: 10),
                child: Image.asset(
                  'images/zxlogo.png',
                  fit: BoxFit.cover,
                ),
              ),
              Text(
                '分销管理系统',
                style: TextStyle(fontSize: 20),
              )
            ],
          ),
        ),
      );

  }
}


class TestTextField extends StatefulWidget {
  @override
  _TestTextFieldState createState() => _TestTextFieldState();
}

class _TestTextFieldState extends State<TestTextField> {
  TextEditingController _textEditingController1 = TextEditingController();
  TextEditingController _textEditingController2 = TextEditingController();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _textEditingController2.text = 'sdf';
    _textEditingController1.text = '1232';
  }
  @override
  Widget build(BuildContext context) {
    return Material(
      child:  Container(

        child: Column(
          children: <Widget>[
            TextField(
              controller: _textEditingController1,
              decoration: InputDecoration(
                  hintText: '用户名', prefixIcon: Icon(Icons.face)),
              maxLength: 20,
            ),
            TextField(
              controller: _textEditingController2,
              decoration: InputDecoration(
                  hintText: 'sdfsdf', prefixIcon: Icon(Icons.face)),
              maxLength: 20,
            )
          ],
        ),

      ),
    );
  }
}

